package com.dingpeikeji.quickdeer.modules.jpush.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;



/**
 * java后台极光推送方式二：使用Java SDK
 */
@SuppressWarnings({ "deprecation", "restriction" })
public class JiguangPush {
    private static final Logger log = LoggerFactory.getLogger(JiguangPush.class);
    private static String masterSecret = "c8b677b51477de45c28f15b7";
    private static String appKey = "f2d4a3f64357df59aeda1238";

    
    public static PushPayload buildPushObject_all_all_alert(String alert) {
	    return PushPayload.alertAll(alert);
	}
    
    /**
     * 全部
     * 极光推送方法(采用java SDK)
     * @param alert
     */
    public static void push(String alert){
        ClientConfig clientConfig = ClientConfig.getInstance();
        JPushClient jpushClient = new JPushClient(masterSecret, appKey, null, clientConfig);
        PushPayload payload = buildPushObject_all_all_alert(alert);
        try {
            PushResult result = jpushClient.sendPush(payload);
            log.info("Got result - " + result);
            Thread.sleep(5000);
            // 请求结束后，调用 NettyHttpClient 中的 close 方法，否则进程不会退出。
            jpushClient.close();
        } catch(Exception e) {
            e.printStackTrace();
        }    
    }
}
